/**
 * 
 */
package travibot.ui.gui.forms.listeners;

import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeSelection;

import travibot.model.Structure;
import travibot.ui.gui.forms.Fields;
import travibot.ui.gui.forms.viewers.FieldsViewer;


/**
 * @author macekpet
 *
 */
public class FieldListSelectionChangedListener implements ISelectionChangedListener {

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
     */
    public void selectionChanged(SelectionChangedEvent arg0) {

        if(arg0.getSelection().isEmpty())
            return;
        
        TreeSelection selection = (TreeSelection)arg0.getSelection();
        
        Structure structure = (Structure)selection.getFirstElement();
        
        FieldsViewer viewer = (FieldsViewer)arg0.getSource();
        
        Fields fields = (Fields)viewer.getTree().getParent();
        
        fields.updateDetails(structure);
    }

}
